<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html>
  <head>
  <base target="_self"/>
  
  <title>表单基本信息添加页面</title>
  	<meta http-equiv="X-UA-Compatible" content="IE=7" />
    <link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
     <script type="text/javascript" src="<%=path %>/jqGrid/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css">
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    $().ready(function() {
    	//获取查询名称
   		var searchname = '<%=request.getParameter("searchname")%>'	
    	// 准备好Options对象
    	var options = {
    	    url:'<%=request.getContextPath() %>/pipePointAction!saveDateSearch.action?searchname='+searchname,
    	    beforeSubmit:checkForm,
    	    dataType:'json',
    	    success: function(data) {
    	      if(data.result=='success'){
				alert("添加成功");
				api.close();
				W.refreshIt();
    	      }else if(data.result=='errorExist'){
    	      	alert("表已存在，请修改表单英文名称！");
    	      	$("#formEnName").focus();
    	      }else{
    	      	alert("系统繁忙，请您稍后再试！");
    	      	api.close();
				W.refreshIt();
    	      }
    	}};
    	
		$('#saveBtn').click(function(){
			$('#pageFrom').ajaxSubmit(options);
			return false;
		});
		
		$('#closeBtn').click(function(){
			api.close();
		});
	});
//表单验证
    function checkForm()
    {     
      var queryTable = $.trim($("#queryTable").val());
      var queryField = $.trim($("#queryField").val()); 
      var conditionTable = $.trim($("#conditionTable").val()); 
      var conditionField = $.trim($("#conditionField").val()); 
      var myPattern = new RegExp("^[a-zA-Z]");
      
      if(queryTable==''){
      		alert("查询表名不能为空!");
			$("#queryTable").focus();
			return false;
      }
	  
	  if(queryField==''){
	  	     alert("查询字段不能为空!");
			 $("#queryField").focus();
			 return false;
	  }
	   if(conditionTable==''){
      		alert("条件表名不能为空!");
			$("#conditionTable").focus();
			return false;
      }
	  
	  if(conditionField==''){
	  	     alert("条件字段不能为空!");
			 $("#conditionField").focus();
			 return false;
	  }
     }
   //验证特殊字符
	function checkExp(inputData){ 
		var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
		var result = inputData.match(regEx);
		if (result == null) {
		return false;
		}
		return true;
	} 
	function countlen(textarea){
	    if (textarea.value.length> 250){
	        alert("最多为250个字符,字符输入超出限制!");
	        textarea.value=textarea.value.substring(0,250);
	    }
	    return true;
	}
	function specialType1(){
		if(document.getElementById("specialColumn").value!=''&&document.getElementById("specialColumn").value!=2){
		
			document.getElementById("r1").style.display="";
			document.getElementById("r2").style.display="";
		}else{
			document.getElementById("r1").style.display="none";
			document.getElementById("r2").style.display="none";
		}
	}
	//选择查询表
	function chooseQueryTable(){
	  /*var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_table_search.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
				if(typeof(datas) == 'undefined'){
				}else{
					callbackForeignTableName(eval('(' + datas + ')'));
				}
				*/
		var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_table_search.jsp?queryTable=queryTable&foreignTableId=foreignTableId&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	    
	    $("#foreignCloumn").val("");
		$("#foreignDisCloumn").val("");		
	}
   //查询表名回调赋值
   function callbackForeignTableName(json){
			$("#queryTable").val(json.form_en_name);
			$("#foreignTableId").val(json.formId);
			$("#foreignCloumn").val("");
			$("#foreignDisCloumn").val("");
   }
   //选择查询字段字段
   function chooseQueryField(){ 		
   		var foreignFormId = $("#foreignTableId").val();
   		if(foreignFormId == ""){
   			alert("请先选择查询表！");
   			return false;
   		}
 		/*var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_cloumn_search.jsp?formId="+foreignFormId+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		}else{
			
			callbackQueryField(eval('(' + datas + ')'));
		}
   		*/
   		var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_cloumn_search.jsp?queryField=queryField&fieldCn="+""+"&formId="+foreignFormId+"&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	    
	   
   }
    //查询字段回调赋值
   function callbackQueryField(datas){
		$("#queryField").val(datas.field_name);
   }
   
   //选择中间表
	function chooseConnectTable(){
		/*
   		var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_table_search.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
				if(typeof(datas) == 'undefined'){
				}else{
					callbackConnectTableName(eval('(' + datas + ')'));
				}
   		*/
	   var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_table_search.jsp?queryTable=connectTable&foreignTableId=connectTableId&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	    
	    $("#foreignCloumn").val("");
		$("#foreignDisCloumn").val("");		
	}
   //查询中间表名回调赋值
   function callbackConnectTableName(json){
			$("#connectTable").val(json.form_en_name);
			$("#connectTableId").val(json.formId);
			$("#foreignCloumn").val("");
			$("#foreignDisCloumn").val("");
   }
   //选择中间查询字段字段
   function chooseConnectField(){
   		var connectTableId = $("#connectTableId").val();
   		if(connectTableId == ""){
   			alert("请先选择中间表！");
   			return false;
   		}
 		/*var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_cloumn_search.jsp?formId="+connectTableId+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		}else{
			
			callbackConnectField(eval('(' + datas + ')'));
		}*/
		var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_cloumn_search.jsp?queryField=connectField&fieldCn="+""+"&formId="+connectTableId+"&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	    
	   
   }
    //查询字段回调赋值
   function callbackConnectField(datas){
		$("#connectField").val(datas.field_name);
   }
    //选择中间表条件字段
   function chooseConnectFieldCon(){
   		var connectTableId = $("#connectTableId").val();
   		if(connectTableId == ""){
   			alert("请先选择中间表！");
   			return false;
   		}
 		/*var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_cloumn_search.jsp?formId="+connectTableId+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		}else{
			
			callbackConnectFieldCon(eval('(' + datas + ')'));
		}*/
		var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_cloumn_search.jsp?queryField=connectFieldCon&fieldCn="+""+"&formId="+connectTableId+"&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	    
	   
   }
    //查询字段回调赋值
   function callbackConnectFieldCon(datas){
		$("#connectFieldCon").val(datas.field_name);
   }
   //选择条件表
   function chooseConditionTable(){
	  /*var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_table_search.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
				if(typeof(datas) == 'undefined'){
				}else{
					callbackConditionTable(eval('(' + datas + ')'));
				}
	   */
	   var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_table_search.jsp?queryTable=conditionTable&foreignTableId=conditionTableId&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	    
	  	$("#foreignCloumn").val("");
		$("#foreignDisCloumn").val("");		
	}
   //选择表表名回调赋值
   function callbackConditionTable(json){
			$("#conditionTable").val(json.form_en_name);
			$("#conditionTableId").val(json.formId);
			$("#foreignCloumn").val("");
			$("#foreignDisCloumn").val("");
   }
   //选择条件字段
   function chooseConditionField(){
   		var conditionTableId = $("#conditionTableId").val();
   		if(conditionTableId == ""){
   			alert("请先选择条件表！");
   			return false;
   		}
 		/*var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_cloumn_search.jsp?formId="+conditionTableId+"&searchType=4"+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		}else{
			
			callbackConditionField(eval('(' + datas + ')'));
		}*/
		var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_cloumn_search.jsp?queryField=conditionField&fieldCn=conditionFieldCn&formId="+conditionTableId+"&searchType=2"+"&temp="+Math.round(Math.random()*10000);
		//var url="<%=basePath%>/resource/choose/choose_table_search.jsp?queryField=conditionField&fieldCn=conditionFieldCn&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	    
   }
    //条件字段回调赋值
   function callbackConditionField(datas){
		$("#conditionField").val(datas.field_name);
		$("#conditionFieldCn").val(datas.cn_name);	
   }   
    //条件主键字段
   function chooseConditionMainField(){
   		var conditionTableId = $("#conditionTableId").val();
   		if(conditionTableId == ""){
   			alert("请先选择条件表！");
   			return false;
   		}
 		/*var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_cloumn_search.jsp?formId="+conditionTableId+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		}else{
			
			callbackConditionMainField(eval('(' + datas + ')'));
		}*/
		var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_cloumn_search.jsp?queryField=conditionMain&fieldCn="+""+"&formId="+conditionTableId+"&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	     
   
   }
    //条件主键字段回调赋值
   function callbackConditionMainField(datas){
		$("#conditionMain").val(datas.field_name);
   }   
     //查询外键字段
   function chooseQueryForeignField(){
   		var foreignFormId = $("#foreignTableId").val();
   		if(foreignFormId == ""){
   			alert("请先选择查询表！");
   			return false;
   		}
 		/*var datas = window.showModalDialog("<%=basePath%>/resource/choose/choose_cloumn_search.jsp?formId="+foreignFormId+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");	
 		if(typeof(datas) == 'undefined'){
		}else{
			
			callbackQueryForeignField(eval('(' + datas + ')'));
		}*/
		var height = 500;
		var width = 800;
		var top=Math.round((window.screen.height-height)/2);
		var left=Math.round((window.screen.width-width)/2);
		var url="<%=basePath%>/resource/choose/choose_cloumn_search.jsp?queryField=queryForeign&fieldCn="+""+"&formId="+foreignFormId+"&temp="+Math.round(Math.random()*10000);
	    window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);	     
		
   }
    //查询外键段回调赋值
   function callbackQueryForeignField(datas){
		$("#queryForeign").val(datas.field_name);
   }   
</script>

 <style type="text/css">
	body{
		background:#ffffff; background-image:url(images/);
	}
</style>


</head>
<body>
  	<form action="" id="pageFrom" name="" method="post">
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
		  <tr>
		    <td align="right" width="10%">查询表名：</td>
		    <td align="left">
				<input type="text" id="queryTable" name="queryTable" value="" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>
				<input type="hidden" id="foreignTableId"  name="foreignTableId" value="" readonly="readonly"/>	
				<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseQueryTable();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		   		<img src="<%=request.getContextPath() %>/images/xh.png"></img>
		    </td>
		    <td align="right" width="10%">查询字段：</td>
		    <td align="left">
				<input type="text" id="queryField" name="queryField" value="" maxlength="20" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>				
		   		<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseQueryField();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		   		<img src="<%=request.getContextPath() %>/images/xh.png"></img>
		    </td>	
		  </tr>
		   <tr>
		    <td align="right" width="10%">中间表名：</td>
		    <td align="left">
				<input type="text" id="connectTable" name="connectTable" value="" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>
				<input type="hidden" id="connectTableId"  name="connectTableId" value="" readonly="readonly"/>	
				
				<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseConnectTable();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		   </tr>
		   <tr> 
		    </td>
		    <td align="right" width="10%">中间表查询字段：</td>
		    <td align="left">
				<input type="text" id="connectField" name="connectField" value="" maxlength="20" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>				
		   		<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseConnectField();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		   		
		    </td>	
		     <td align="right" width="10%">中间表条件字段：</td>
		    <td align="left">
				<input type="text" id="connectFieldCon" name="connectFieldCon" value="" maxlength="20" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>				
		   		<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseConnectFieldCon();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		   		
		    </td>	
		  </tr>
		  <tr> 
		    <td align="right" width="10%">条件表名：</td>
		    <td align="left">
				<input type="text" id="conditionTable" name="conditionTable" value="" maxlength="20" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>
				<input type="hidden" id="conditionTableId"  name="conditionTableId" value="" readonly="readonly"/>
		   		<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseConditionTable();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		    	<img src="<%=request.getContextPath() %>/images/xh.png"></img>
		    </td>
		    <td align="right" width="20%">条件字段：</td>
		    <td align="left">
				<input type="text" id="conditionField" name="conditionField" value="" maxlength="20" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>
				<input type="text" id="conditionFieldCn" name="conditionFieldCn" value="" maxlength="20" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>				
		   		<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseConditionField();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		    	<img src="<%=request.getContextPath() %>/images/xh.png"></img>
		    </td>		 
		  </tr>
		    <tr> 
		    <td align="right" width="20%">条件主键：</td>
		    <td align="left">
				<input type="text" id="conditionMain" name="conditionMain" value="" maxlength="20" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>			
		   		<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseConditionMainField();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		    </td>
		    <td align="right" width="20%">查询外键：</td>
		    <td align="left">
				<input type="text" id="queryForeign" name="queryForeign" value="" maxlength="20" style="border: 1px solid #999;padding: 5px;width: 160px;" maxlength="40"/>
		   		<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseQueryForeignField();" title="选择" style="margin-bottom:-6px;cursor:hand;" />
		    </td>		 
		  </tr>
		  <tr>
		    <td align="center" colspan="4" >
		    	<input type="button" id="saveBtn" value="提 交" class="form_bt_orange" />
		      	<input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		    </td>
		  </tr>
		</table>
		<input type="hidden" id="formType" name="formType" value="<%=request.getParameter("fromtype") %>" />
	</form>
  </body>
</html>